package com.atguigu.crowd.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atguigu.crowd.entity.Type;
import com.atguigu.crowd.entity.TypeExample;
import com.atguigu.crowd.entity.TypeExample.Criteria;
import com.atguigu.crowd.mapper.TypeMapper;
import com.atguigu.crowd.service.api.TypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class TypeServiceImpl implements TypeService {
	
	@Autowired
	private TypeMapper typeMapper;

	@Override
	public PageInfo<Type> getTypePageInfo(Integer pageNum, Integer pageSize, String keyword) {
		PageHelper.startPage(pageNum, pageSize);
		List<Type> list = typeMapper.selectProjectTypeByKeyword(keyword);
		return new PageInfo<>(list);
	}

	@Override
	public void addProjectType(Type type) {
		typeMapper.insert(type);
	}

	@Override
	public void editProjectType(Type type) {
		typeMapper.updateByPrimaryKeySelective(type);
	}

	@Override
	public void removeType(List<Integer> ids) {
		TypeExample typeExample = new TypeExample();
		Criteria createCriteria = typeExample.createCriteria();
		createCriteria.andIdIn(ids);
		typeMapper.deleteByExample(typeExample);
	}


}
